<%-- 
    Document   : student_man
    Created on : Jun 1, 2016, 2:16:58 PM
    Author     : niugao
    学生管理页面
--%>

<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="java.util.List" %>
<%@ page import="com.situ.studentmanagement.dao.StudentMapper" %>
<%@ page import="com.situ.studentmanagement.model.Student" %>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ include file="common.jsp" %>

<%
    String HTML_ATTR_NAME="studentid";
%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><%=g_title%>
    </title>

    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <style>
        table img {
            width: 16px;
        }

        table img:hover {
            cursor: pointer;
        }
    </style>

    <script>

        //当点击删除图片的时候调用
        function deleteRow(img) {
            //出对话框，让用户确认是否删除
            var id = $(img).attr("<%=HTML_ATTR_NAME%>");
            $("#dialog").attr("<%=HTML_ATTR_NAME%>", id);
            $("#dialog").modal("show");
        }

        //点了对话框中的确定删除按钮
        function executeDel() {
            var id = $("#dialog").attr("<%=HTML_ATTR_NAME%>");
            //关掉对话框
            $("#dialog").modal("hide");
            //导航到删除页面
            $.getJSON("/api/student/deletStudent",
                    {
                        id:id
                    },
                    function (json,status) {
                        var r=json.deleId;
                        var obj=$("#"+r);
                        $("#"+r).remove();
                    }
            );
        }

        //点了对话框中的不删按钮
        function cancelDel() {
            //关掉对话框
            $("#dialog").modal("hide");
        }
    </script>


</head>
<body>
<div>
    <!-- 很多页面都使用这个顶部栏，所以拿出来放到一个单独文件中 -->
    <jsp:include page="componse/top_bar.jsp" flush="true"/>

    <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
            <a class="navbar-brand" href="/main">返回</a>
        </div>
        <div>
            <ul class="nav navbar-nav">
                <li><a href="/class/class_man">部门管理</a></li>
                <li class="active"><a href="/Saccount/student_man">员工管理</a></li>
                <li><a href="/Saccount/addStudent">添加员工</a></li>
            </ul>
        </div>
    </nav>

    <div class="container">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>id</th>
                <th>名字</th>
                <th>电话</th>
                <th>email</th>
                <th>性别</th>
                <th>住址</th>
                <th>部门</th>
                <th></th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            <jstl:forEach items="${students}" var="std">
                <tr id="${std.id}">
                    <td>${std.id}</td>
                    <td>${std.name}</td>
                    <td>${std.phone}</td>
                    <td>${std.email}</td>
                    <td>${std.sexChar}</td>
                    <td>${std.address}</td>
                    <td>${std.class_id}</td>
                    <td><img <%=HTML_ATTR_NAME%>='${std.id}' onclick='deleteRow(this)' src='../img/del.png'/></td>
                    <td><a href="/Saccount/modifyStudent?modify_id=${std.id}"><img src='../img/modify.png'/></a></td>
                </tr>
            </jstl:forEach>
            </tbody>
        </table>
    <%--</div>--%>
    <%--<div><a href="add_student.jsp">登记学生</a></div>--%>
<%--</div>--%>

<!-- 模态框（Modal） -->
<div class="modal fade" id="dialog" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    警告
                </h4>
            </div>
            <div class="modal-body">
                你确定要删除这个员工吗?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="cancelDel()">
                    不
                </button>
                <button type="button" class="btn btn-primary" onclick="executeDel()">
                    删吧，别废话
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
</html>
